home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry2.iso / Tank Wars 3D / src / GAMEPLAY.CPP next >
Encoding:
C/C++ Source or Header  |  2003-03-17  |  31.8 KB  |  903 lines

  1. #include <math.h>
  2. #include <dinput.h>
  3.  
  4. #include "tankwars.h"
  5.  
  6. void createbigexplosion(int xpos, int ypos);
  7.  
  8. // Direct Input
  9. extern LPDIRECTINPUT7        g_DI;
  10. // Keyboard Device
  11. extern LPDIRECTINPUTDEVICE7    g_KDIDev;
  12.  
  13. extern BYTE    key[256];
  14. extern bool mousebutton[2];
  15.  
  16. int grid[30][20];
  17. float cameraangle;
  18. float fps;
  19.  
  20. c_player player[2];
  21.  
  22. c_explosion explosion[50];
  23. int nextexplosionslot;
  24.  
  25. c_missle missle[20];
  26. int nextmissleslot;
  27.  
  28. c_smoke smoke[50];
  29. int nextsmokeslot;
  30.  
  31. c_grenade grenade[20];
  32. int nextgrenadeslot;
  33.  
  34. c_particle particle[500];
  35. int nextparticleslot;
  36.  
  37. c_debris debris[100];
  38. int nextdebrisslot;
  39.  
  40. unsigned long wall;
  41.  
  42. int poweruptime;
  43.  
  44. int winner;
  45.  
  46. int fogenabled;
  47. int timeofday;
  48. int raindensity;
  49.  
  50. void maingame(void)
  51. {
  52.     MSG        msg;                        // Windows Message Structure
  53.     BOOL    finished=FALSE;                // Bool Variable To Exit Loop
  54.  
  55.     int i, i2, x, y;
  56.  
  57.     _2Df futurepos;
  58.  
  59.     // The position of the mouse:
  60.     POINT mousepos;
  61.  
  62.     // Variables to aid in calculation of Frames per second:
  63.     _int64 t, m, clckpersec;
  64.  
  65.     // Calculates how many clock ticks per second:
  66.     QueryPerformanceFrequency((LARGE_INTEGER*)&clckpersec);
  67.  
  68.     // Frame limiter:
  69.     int framelimit=1;
  70.  
  71.     while(!finished)                                    // Loop That Runs While done=FALSE
  72.     {
  73.         if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))    // Is There A Message Waiting?
  74.         {
  75.             if (msg.message==WM_QUIT)                // Have We Received A Quit Message?
  76.                 finished=TRUE;                        // If So done=TRUE
  77.             else                                    // If Not, Deal With Window Messages
  78.             {
  79.                 TranslateMessage(&msg);                // Translate The Message
  80.                 DispatchMessage(&msg);                // Dispatch The Message
  81.             }
  82.         }
  83.         else                                        // If There Are No Messages
  84.         {
  85.             QueryPerformanceCounter((LARGE_INTEGER*)&t);
  86.             HRESULT hr = g_KDIDev->GetDeviceState(sizeof(key), &key);    // Get The Keys That Have Been Pressed ( Add )
  87.             // BEGINNING OF MAIN LOOP
  88.  
  89.             for(i=0; i<2; i++)
  90.             {
  91.                 if(key[player[i].control.right] & 0x80)
  92.                 {
  93.                     player[i].rot+=15;
  94.                     if(player[i].rot>=360)
  95.                         player[i].rot=player[i].rot-360;
  96.                 }
  97.                 if(key[player[i].control.left] & 0x80)
  98.                 {
  99.                     player[i].rot-=15;
  100.                     if(player[i].rot<0)
  101.                         player[i].rot=360+player[i].rot;
  102.                 }
  103.                 if(key[player[i].control.forward] || key[player[i].control.backward] & 0x80)
  104.                 {
  105.                     if(key[player[i].control.forward] & 0x80)
  106.                     {
  107.                         futurepos.x=player[i].pos.x+(float)cos(player[i].rot*PI/180)*2;
  108.                         futurepos.y=player[i].pos.y+(float)sin(player[i].rot*PI/180)*2;
  109.                     }
  110.                     if(key[player[i].control.backward] & 0x80)
  111.                     {
  112.                         futurepos.x=player[i].pos.x-(float)cos(player[i].rot*PI/180)*2;
  113.                         futurepos.y=player[i].pos.y-(float)sin(player[i].rot*PI/180)*2;
  114.                     }
  115.  
  116.  
  117.                     if(grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==BRICK1 || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==BRICK0 || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==TREE || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==TRUNK || grid[(int)(player[i].pos.x/10-1)][(int)(player[i].pos.y/10)]==i+BLUEGATE)
  118.                     {
  119.                         if(futurepos.x-3<((int)player[i].pos.x/(int)10-(int)1)*(int)10+(int)10)
  120.                             futurepos.x=(float)(((int)(player[i].pos.x/10)-1)*10+10+3);
  121.                     }
  122.                     if(grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==BRICK1 || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==BRICK0 || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==TREE || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==TRUNK || grid[(int)(player[i].pos.x/10+1)][(int)(player[i].pos.y/10)]==i+BLUEGATE)
  123.                     {
  124.                         if(futurepos.x+3>((int)player[i].pos.x/(int)10+(int)1)*(int)10)
  125.                             futurepos.x=(float)(((int)(player[i].pos.x/10)+1)*10-3);
  126.                     }
  127.                     if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==BRICK1 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==BRICK0 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==TREE || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==TRUNK || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10-1)]==i+BLUEGATE)
  128.                     {
  129.                         if(futurepos.y-3<((int)player[i].pos.y/(int)10-(int)1)*(int)10+(int)10)
  130.                             futurepos.y=(float)(((int)(player[i].pos.y/10)-1)*10+10+3);
  131.                     }
  132.                     if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==BRICK1 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==BRICK0 || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==TREE || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==TRUNK || grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10+1)]==i+BLUEGATE)
  133.                     {
  134.                         if(futurepos.y+3>((int)player[i].pos.y/(int)10+(int)1)*(int)10)
  135.                             futurepos.y=(float)(((int)(player[i].pos.y/10)+1)*10-3);
  136.                     }
  137.  
  138.                     if(grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==BRICK1 || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==BRICK0 || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==TREE || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==TRUNK || grid[(int)(futurepos.x/10)][(int)(futurepos.y/10)]==i+BLUEGATE)
  139.                     {
  140.                         futurepos.x=player[i].pos.x;
  141.                         futurepos.y=player[i].pos.y;
  142.                     }
  143.                     
  144.  
  145.                     if(futurepos.x-3<0)
  146.                         futurepos.x=3;
  147.                     if(futurepos.x+3>300)
  148.                         futurepos.x=297;
  149.                     if(futurepos.y-3<0)
  150.                         futurepos.y=3;
  151.                     if(futurepos.y+3>200)
  152.                         futurepos.y=197;
  153.  
  154.                     if(wall>0)
  155.                     {
  156.                         if(i==0)
  157.                             if(futurepos.x+3>150)
  158.                                 futurepos.x=147;
  159.                         if(i==1)
  160.                             if(futurepos.x-3<150)
  161.                                 futurepos.x=153;
  162.                     }
  163.  
  164.                     player[i].pos.x=futurepos.x;
  165.                     player[i].pos.y=futurepos.y;
  166.                 }
  167.  
  168.                 // Calculate player's new build position:
  169.                 player[i].buildpos.x=(int)((float)(player[i].pos.x+cos(player[i].rot*PI/180)*10)/(float)10);
  170.                 player[i].buildpos.y=(int)((float)(player[i].pos.y+sin(player[i].rot*PI/180)*10)/(float)10);
  171.  
  172.                 // Check if player switches mode:
  173.                 if(key[player[i].control.rightchange] & 0x80 && !player[i].control.rightf)
  174.                 {
  175.                     player[i].control.rightf=1;
  176.                     player[i].mode++;
  177.                     if(player[i].mode>3)
  178.                         player[i].mode=0;
  179.                 }
  180.                 if(!(key[player[i].control.rightchange] & 0x80))
  181.                     player[i].control.rightf=0;
  182.  
  183.                 if((key[player[i].control.leftchange] & 0x80) && (!player[i].control.leftf))
  184.                 {
  185.                     player[i].control.leftf=1;
  186.                     player[i].mode--;
  187.                     if(player[i].mode<0)
  188.                         player[i].mode=3;
  189.                 }
  190.                 if(!(key[player[i].control.leftchange] & 0x80))
  191.                     player[i].control.leftf=0;
  192.  
  193.                 // Check if player wants to build a Brick
  194.                 if(key[player[i].control.fire] & 0x80 && player[i].mode==BRICK_MODE && player[i].ammo.bricks>0 && player[i].rebirth==0)
  195.                 {
  196.                     if(grid[player[i].buildpos.x][player[i].buildpos.y]==EMPTY && player[i].buildpos.x>=0 && player[i].buildpos.x<30 && player[i].buildpos.y>=0 && player[i].buildpos.y<20)
  197.                     {
  198.                         grid[player[i].buildpos.x][player[i].buildpos.y]=BRICK1;
  199.                         player[i].ammo.bricks--;
  200.                         if(player[i].pos.x-3<player[i].buildpos.x*10+10 &&
  201.                            player[i].pos.x+3>player[i].buildpos.x*10 &&
  202.                            player[i].pos.y-3<player[i].buildpos.y*10+10 &&
  203.                            player[i].pos.y+3>player[i].buildpos.y*10)
  204.                         {
  205.                             player[i].pos.x-=(float)cos(player[i].rot*PI/180)*4;
  206.                             player[i].pos.y-=(float)sin(player[i].rot*PI/180)*4;
  207.                         }
  208.                     }
  209.                 }
  210.                 // Check if player wants to build a Mine
  211.                 if(key[player[i].control.fire] & 0x80 && player[i].mode==MINE_MODE && player[i].ammo.mines>0 && player[i].rebirth==0)
  212.                 {
  213.                     if(grid[player[i].buildpos.x][player[i].buildpos.y]==EMPTY && player[i].buildpos.x>=0 && player[i].buildpos.x<30 && player[i].buildpos.y>=0 && player[i].buildpos.y<20)
  214.                     {
  215.                         grid[player[i].buildpos.x][player[i].buildpos.y]=MINE;
  216.                         player[i].ammo.mines--;
  217.                         if(player[i].pos.x-3<player[i].buildpos.x*10+10 &&
  218.                            player[i].pos.x+3>player[i].buildpos.x*10 &&
  219.                            player[i].pos.y-3<player[i].buildpos.y*10+10 &&
  220.                            player[i].pos.y+3>player[i].buildpos.y*10)
  221.                         {
  222.                             player[i].pos.x-=(float)cos(player[i].rot*PI/180)*4;
  223.                             player[i].pos.y-=(float)sin(player[i].rot*PI/180)*4;
  224.                         }
  225.                     }
  226.                 }
  227.  
  228.                 // Check if player wants to fire a missle:
  229.                 if(key[player[i].control.fire] & 0x80 && player[i].mode==MISSLE_MODE && player[i].ammo.missles>0 && player[i].missleload==0 && player[i].rebirth==0)
  230.                 {
  231.                     PlaySound("Data/Missle.wav", NULL, SND_ASYNC);
  232.                     player[i].ammo.missles--;
  233.                     player[i].missleload=20;
  234.                     missle[nextmissleslot].active=1;
  235.                     missle[nextmissleslot].rot=player[i].rot;
  236.                     missle[nextmissleslot].pos.x=player[i].pos.x+(float)cos(player[i].rot*PI/180)*4;
  237.                     missle[nextmissleslot].pos.y=player[i].pos.y+(float)sin(player[i].rot*PI/180)*4;
  238.                     missle[nextmissleslot].start.x=(int)(player[i].pos.x/10);
  239.                     missle[nextmissleslot].start.y=(int)(player[i].pos.y/10);
  240.                     missle[nextmissleslot].smoke=nextsmokeslot;
  241.  
  242.                     smoke[nextsmokeslot].rot=player[i].rot;
  243.                     smoke[nextsmokeslot].pos.x=player[i].pos.x+(float)cos(player[i].rot*PI/180)*4;
  244.                     smoke[nextsmokeslot].pos.y=player[i].pos.y+(float)sin(player[i].rot*PI/180)*4;
  245.                     smoke[nextsmokeslot].active=1;
  246.                     smoke[nextsmokeslot].life=0;
  247.                     smoke[nextsmokeslot].length=0;
  248.                     smoke[nextsmokeslot].stillmoving=1;
  249.  
  250.                     nextmissleslot=0;
  251.                     while(missle[nextmissleslot].active)
  252.                         nextmissleslot++;
  253.  
  254.                     nextsmokeslot=0;
  255.                     while(smoke[nextsmokeslot].active)
  256.                         nextsmokeslot++;
  257.                 }
  258.  
  259.                 // Check if player wants to fire a grenade:
  260.                 if(key[player[i].control.fire] & 0x80 && player[i].mode==GRENADE_MODE && player[i].ammo.grenades>0 && player[i].grenadeload==0 && player[i].rebirth==0)
  261.                 {
  262.                     if(grid[player[i].buildpos.x][player[i].buildpos.y]==EMPTY && player[i].buildpos.x>=0 && player[i].buildpos.x<30 && player[i].buildpos.y>=0 && player[i].buildpos.y<20)
  263.                     {
  264.                         PlaySound("Data/Gren_tick.wav", NULL, SND_ASYNC);
  265.                         player[i].ammo.grenades--;
  266.                         player[i].grenadeload=50;
  267.                         grenade[nextgrenadeslot].stage=25;
  268.                         grenade[nextgrenadeslot].pos.x=player[i].buildpos.x;
  269.                         grenade[nextgrenadeslot].pos.y=player[i].buildpos.y;
  270.                         nextgrenadeslot=0;
  271.                         while(grenade[nextgrenadeslot].stage>0)
  272.                             nextgrenadeslot++;
  273.                     }
  274.                 }
  275.  
  276.  
  277.                 // Check if player crashed into a Mine:
  278.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==MINE)
  279.                 {
  280.                     if(sqrt((player[i].pos.x-((int)(player[i].pos.x/10)*10+5))*(player[i].pos.x-((int)(player[i].pos.x/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5)))<5)
  281.                     {
  282.                         grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
  283.  
  284.                         explosion[nextexplosionslot].stage=19;
  285.                         explosion[nextexplosionslot].pos.x=(int)(player[i].pos.x/10);
  286.                         explosion[nextexplosionslot].pos.y=(int)(player[i].pos.y/10);
  287.                         nextexplosionslot=0;
  288.                         while(explosion[nextexplosionslot].stage>0)
  289.                         {
  290.                             nextexplosionslot++;
  291.                             if(nextexplosionslot==50)
  292.                             {
  293.                                 nextexplosionslot=0;
  294.                                 explosion[0].stage=0;
  295.                             }
  296.                         }
  297.                         for(i2=0; i2<5; i2++)
  298.                         {
  299.                             debris[nextdebrisslot].active=1;
  300.                             debris[nextdebrisslot].pos.x=(float)((int)(player[i].pos.x/10)*10+5);
  301.                             debris[nextdebrisslot].pos.y=(float)((int)(player[i].pos.y/10)*10+5);
  302.                             debris[nextdebrisslot].pos.z=0.0f;
  303.                             debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  304.                             debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  305.                             debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
  306.                             if(i==0)
  307.                             {
  308.                                 debris[nextdebrisslot].color.x=0.6f;
  309.                                 debris[nextdebrisslot].color.y=0.1f;
  310.                                 debris[nextdebrisslot].color.z=0.0f;
  311.                             }
  312.                             if(i==1)
  313.                             {
  314.                                 debris[nextdebrisslot].color.x=0.0f;
  315.                                 debris[nextdebrisslot].color.y=0.1f;
  316.                                 debris[nextdebrisslot].color.z=0.6f;
  317.                             }
  318.  
  319.                             nextdebrisslot=0;
  320.                             while(debris[nextdebrisslot].active==1)
  321.                             {
  322.                                 nextdebrisslot++;
  323.                                 if(nextdebrisslot==500)
  324.                                 {
  325.                                     nextdebrisslot=0;
  326.                                     debris[0].active=0;
  327.                                 }
  328.                             }
  329.                         }
  330.                         for(i2=0; i2<100; i2++)
  331.                         {
  332.                             particle[nextparticleslot].life=1;
  333.                             particle[nextparticleslot].pos.x=(float)((int)(player[i].pos.x/10)*10+5);
  334.                             particle[nextparticleslot].pos.y=(float)((int)(player[i].pos.y/10)*10+5);
  335.                             particle[nextparticleslot].pos.z=0.0f;
  336.                             particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  337.                             particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  338.                             particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
  339.                             nextparticleslot=0;
  340.                             while(particle[nextparticleslot].life>0)
  341.                             {
  342.                                 nextparticleslot++;
  343.                                 if(nextparticleslot==500)
  344.                                 {
  345.                                     nextparticleslot=0;
  346.                                     particle[0].life=0;
  347.                                 }
  348.                             }
  349.                         }
  350.                         
  351.                         PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
  352.                         player[i].rebirth=100;
  353.                         player[i].lives--;
  354.                         player[i].pos.x=(float)(player[i].startpos.x*10+5);
  355.                         player[i].pos.y=(float)(player[i].startpos.y*10+5);
  356.                         if(i==0)
  357.                             player[i].rot=0;
  358.                         if(i==1)
  359.                             player[i].rot=180;
  360.                     }
  361.                 }
  362.  
  363.                 // Check if player got a power up:
  364.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==LIFE_POWERUP)
  365.                 {
  366.                     player[i].lives++;
  367.                     grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
  368.                 }
  369.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==BRICK_POWERUP)
  370.                 {
  371.                     player[i].ammo.bricks+=10;
  372.                     grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
  373.                 }
  374.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==MINE_POWERUP)
  375.                 {
  376.                     player[i].ammo.mines+=10;
  377.                     grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
  378.                 }
  379.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==MISSLE_POWERUP)
  380.                 {
  381.                     player[i].ammo.missles+=10;
  382.                     grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
  383.                 }
  384.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==GRENADE_POWERUP)
  385.                 {
  386.                     player[i].ammo.grenades+=5;
  387.                     grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]=EMPTY;
  388.                 }
  389.  
  390.                 // Check if player got the enemys flag:
  391.                 if(grid[(int)(player[i].pos.x/10)][(int)(player[i].pos.y/10)]==i+BLUEFLAG)
  392.                 {
  393.                     if(sqrt((player[i].pos.x-((int)(player[i].pos.x/10)*10+5))*(player[i].pos.x-((int)(player[i].pos.x/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5))+(player[i].pos.y-(int)((player[i].pos.y/10)*10+5)))<5)
  394.                     {
  395.                         PlaySound("Data/Flag_Cap.wav", NULL, SND_SYNC);
  396.                         winner=i;
  397.                         finished=TRUE;
  398.                     }
  399.                 }
  400.  
  401.                 // Reload player's missles and grenades
  402.                 if(player[i].missleload>0)
  403.                     player[i].missleload--;
  404.                 if(player[i].grenadeload>0)
  405.                     player[i].grenadeload--;
  406.  
  407.                 // Check player rebirth:
  408.                 if(player[i].rebirth>0)
  409.                 {
  410.                     player[i].rebirth--;
  411.                     player[i].pos.x=(float)(player[i].startpos.x*10+5);
  412.                     player[i].pos.y=(float)(player[i].startpos.y*10+5);
  413.                     if(i==0)
  414.                         player[i].rot=0;
  415.                     if(i==1)
  416.                         player[i].rot=180;
  417.                 }
  418.             }
  419.  
  420.             // Add a powerup
  421.             poweruptime--;
  422.             if(poweruptime==0)
  423.             {
  424.                 poweruptime=125;
  425.                 x=rand()%30;
  426.                 y=rand()%20;
  427.                 i=0;
  428.                 while(grid[x][y]!=EMPTY && i<600)
  429.                 {
  430.                     x=rand()%30;
  431.                     y=rand()%20;
  432.                     i++;
  433.                 }
  434.                 i=rand()%5+10;
  435.                 grid[x][y]=i;
  436.             }
  437.  
  438.             // Check if both Tanks crashed into each other:
  439.             if(sqrt((player[0].pos.x-player[1].pos.x)*(player[0].pos.x-player[1].pos.x)+(player[0].pos.y-player[1].pos.y)*(player[0].pos.y-player[1].pos.y))<=6)
  440.             {
  441.                 explosion[nextexplosionslot].stage=19;
  442.                 explosion[nextexplosionslot].pos.x=(int)((player[0].pos.x+player[1].pos.x)/2/10);
  443.                 explosion[nextexplosionslot].pos.y=(int)((player[0].pos.y+player[1].pos.y)/2/10);
  444.                 nextexplosionslot=0;
  445.                 while(explosion[nextexplosionslot].stage>0)
  446.                 {
  447.                     nextexplosionslot++;
  448.                     if(nextexplosionslot==50)
  449.                     {
  450.                         nextexplosionslot=0;
  451.                         explosion[0].stage=0;
  452.                     }
  453.                 }
  454.                         for(i2=0; i2<10; i2++)
  455.                         {
  456.                             debris[nextdebrisslot].active=1;
  457.                             debris[nextdebrisslot].pos.x=(float)((int)((player[0].pos.x+player[1].pos.x)/2/10)*10+5);
  458.                             debris[nextdebrisslot].pos.y=(float)((int)((player[0].pos.y+player[1].pos.y)/2/10)*10+5);
  459.                             debris[nextdebrisslot].pos.z=0.0f;
  460.                             debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  461.                             debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  462.                             debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
  463.                             if(i2<5)
  464.                             {
  465.                                 debris[nextdebrisslot].color.x=0.6f;
  466.                                 debris[nextdebrisslot].color.y=0.1f;
  467.                                 debris[nextdebrisslot].color.z=0.0f;
  468.                             }
  469.                             else
  470.                             {
  471.                                 debris[nextdebrisslot].color.x=0.0f;
  472.                                 debris[nextdebrisslot].color.y=0.1f;
  473.                                 debris[nextdebrisslot].color.z=0.6f;
  474.                             }
  475.  
  476.                             nextdebrisslot=0;
  477.                             while(debris[nextdebrisslot].active==1)
  478.                             {
  479.                                 nextdebrisslot++;
  480.                                 if(nextdebrisslot==500)
  481.                                 {
  482.                                     nextdebrisslot=0;
  483.                                     debris[0].active=0;
  484.                                 }
  485.                             }
  486.                         }
  487.                 for(i2=0; i2<100; i2++)
  488.                 {
  489.                     particle[nextparticleslot].life=1;
  490.                     particle[nextparticleslot].pos.x=(float)((int)((player[0].pos.x+player[1].pos.x)/2/10)*10+5);
  491.                     particle[nextparticleslot].pos.y=(float)((int)((player[0].pos.y+player[1].pos.y)/2/10)*10+5);
  492.                     particle[nextparticleslot].pos.z=0.0f;
  493.                     particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  494.                     particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  495.                     particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
  496.                     nextparticleslot=0;
  497.                     while(particle[nextparticleslot].life>0)
  498.                     {
  499.                         nextparticleslot++;
  500.                         if(nextparticleslot==500)
  501.                         {
  502.                             nextparticleslot=0;
  503.                             particle[0].life=0;
  504.                         }
  505.                     }
  506.                 }
  507.                 
  508.                 PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
  509.                 player[0].rebirth=100;
  510.                 player[1].rebirth=100;
  511.                 player[0].lives--;
  512.                 player[1].lives--;
  513.                 
  514.                 player[0].pos.x=(float)(player[0].startpos.x*10+5);
  515.                 player[0].pos.y=(float)(player[0].startpos.y*10+5);
  516.                 player[0].rot=0;
  517.                 player[1].pos.x=(float)(player[1].startpos.x*10+5);
  518.                 player[1].pos.y=(float)(player[1].startpos.y*10+5);
  519.                 player[1].rot=180;
  520.             }
  521.  
  522.             // Lower the wall:
  523.             if(wall>0)
  524.                 wall--;
  525.  
  526.             // Move all the missles:
  527.             for(i=0; i<20; i++)
  528.             {
  529.                 if(missle[i].active)
  530.                 {
  531.                     missle[i].pos.x+=(float)cos(missle[i].rot*PI/180)*4;
  532.                     missle[i].pos.y+=(float)sin(missle[i].rot*PI/180)*4;
  533.  
  534.                     for(i2=0; i2<2; i2++)
  535.                     {
  536.                         if(sqrt((missle[i].pos.x-player[i2].pos.x)*(missle[i].pos.x-player[i2].pos.x)+(missle[i].pos.y-player[i2].pos.y)*(missle[i].pos.y-player[i2].pos.y))<6 && player[i2].rebirth==0)
  537.                         {
  538.                             explosion[nextexplosionslot].stage=19;
  539.                             explosion[nextexplosionslot].pos.x=(int)(player[i2].pos.x/10);
  540.                             explosion[nextexplosionslot].pos.y=(int)(player[i2].pos.y/10);
  541.                             nextexplosionslot=0;
  542.                             while(explosion[nextexplosionslot].stage>0)
  543.                             {
  544.                                 nextexplosionslot++;
  545.                                 if(nextexplosionslot==50)
  546.                                 {
  547.                                     nextexplosionslot=0;
  548.                                     explosion[0].stage=0;
  549.                                 }
  550.                             }
  551.                             for(x=0; x<5; x++)
  552.                             {
  553.                                 debris[nextdebrisslot].active=1;
  554.                                 debris[nextdebrisslot].pos.x=(float)((int)(player[i2].pos.x/10)*10+5);
  555.                                 debris[nextdebrisslot].pos.y=(float)((int)(player[i2].pos.y/10)*10+5);
  556.                                 debris[nextdebrisslot].pos.z=0.0f;
  557.                                 debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  558.                                 debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  559.                                 debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
  560.                                 if(i2==0)
  561.                                 {
  562.                                     debris[nextdebrisslot].color.x=0.6f;
  563.                                     debris[nextdebrisslot].color.y=0.1f;
  564.                                     debris[nextdebrisslot].color.z=0.0f;
  565.                                 }
  566.                                 if(i2==1)
  567.                                 {
  568.                                     debris[nextdebrisslot].color.x=0.0f;
  569.                                     debris[nextdebrisslot].color.y=0.1f;
  570.                                     debris[nextdebrisslot].color.z=0.6f;
  571.                                 }
  572.                                 
  573.                                 nextdebrisslot=0;
  574.                                 while(debris[nextdebrisslot].active==1)
  575.                                 {
  576.                                     nextdebrisslot++;
  577.                                     if(nextdebrisslot==500)
  578.                                     {
  579.                                         nextdebrisslot=0;
  580.                                         debris[0].active=0;
  581.                                     }
  582.                                 }
  583.                             }
  584.                             for(x=0; x<100; x++)
  585.                             {
  586.                                 particle[nextparticleslot].life=1;
  587.                                 particle[nextparticleslot].pos.x=(float)((int)(player[i2].pos.x/10)*10+5);
  588.                                 particle[nextparticleslot].pos.y=(float)((int)(player[i2].pos.y/10)*10+5);
  589.                                 particle[nextparticleslot].pos.z=0.0f;
  590.                                 particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  591.                                 particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  592.                                 particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
  593.                                 nextparticleslot=0;
  594.                                 while(particle[nextparticleslot].life>0)
  595.                                 {
  596.                                     nextparticleslot++;
  597.                                     if(nextparticleslot==500)
  598.                                     {
  599.                                         nextparticleslot=0;
  600.                                         particle[0].life=0;
  601.                                     }
  602.                                 }
  603.                             }
  604.                             missle[i].active=0;
  605.                             smoke[missle[i].smoke].stillmoving=0;
  606.                             if(i<nextmissleslot)
  607.                                 nextmissleslot=0;
  608.                             PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
  609.                             player[i2].rebirth=100;
  610.                             player[i2].lives--;
  611.                             player[i2].pos.x=(float)(player[i2].startpos.x*10+5);
  612.                             player[i2].pos.y=(float)(player[i2].startpos.y*10+5);
  613.                             if(i2==0)
  614.                                 player[i2].rot=0;
  615.                             if(i2==1)
  616.                                 player[i2].rot=180;
  617.                         }
  618.                     }
  619.  
  620.                     for(y=-1; y<2; y++)
  621.                     {
  622.                         for(x=-1; x<2; x++)
  623.                         {
  624.                             if((int)(missle[i].pos.x/10)+x>=0 && (int)(missle[i].pos.x/10)+x<30 && (int)(missle[i].pos.y/10)+y>=0 && (int)(missle[i].pos.y/10)+y<20)
  625.                             {
  626.                                 if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=EMPTY && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=MINE && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=REDFLAG && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=BLUEFLAG && grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]!=TRUNK)
  627.                                 {
  628.                                     if(missle[i].pos.x-3<(int)(missle[i].pos.x/10+x)*10+10 &&
  629.                                         missle[i].pos.x+3>(int)(missle[i].pos.x/10+x)*10 &&
  630.                                         missle[i].pos.y-3<(int)(missle[i].pos.y/10+y)*10+10 &&
  631.                                         missle[i].pos.y+3>(int)(missle[i].pos.y/10+y)*10)
  632.                                     {
  633.                                         i2=0;
  634.                                         if((int)(missle[i].pos.x/10)+x>=missle[i].start.x-1 && (int)(missle[i].pos.x/10)+x<=missle[i].start.x+1 && (int)(missle[i].pos.y/10)+y>=missle[i].start.y-1 && (int)(missle[i].pos.y/10)+y<=missle[i].start.y+1 && (grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK1 || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK0))
  635.                                             i2=1;
  636.                                         if(i2==0)
  637.                                         {
  638.                                             PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
  639.                                             if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK1)
  640.                                                 grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=BRICK0;
  641.                                             else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK0)
  642.                                                 grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=EMPTY;
  643.                                             else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==TREE)
  644.                                                 grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=TRUNK;
  645.                                             else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==TREE)
  646.                                                 grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=TRUNK;
  647.                                             else if(grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==LIFE_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==BRICK_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==MINE_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==MISSLE_POWERUP || grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]==GRENADE_POWERUP)
  648.                                             {
  649.                                                 grid[(int)(missle[i].pos.x/10)+x][(int)(missle[i].pos.y/10)+y]=EMPTY;
  650.                                                 createbigexplosion((int)(missle[i].pos.x/10)+x, (int)(missle[i].pos.y/10)+y);
  651.                                             }
  652.                                             explosion[nextexplosionslot].stage=19;
  653.                                             explosion[nextexplosionslot].pos.x=(int)(missle[i].pos.x/10)+x;
  654.                                             explosion[nextexplosionslot].pos.y=(int)(missle[i].pos.y/10)+y;
  655.                                             nextexplosionslot=0;
  656.                                             while(explosion[nextexplosionslot].stage>0)
  657.                                             {
  658.                                                 nextexplosionslot++;
  659.                                                 if(nextexplosionslot==50)
  660.                                                 {
  661.                                                     nextexplosionslot=0;
  662.                                                     explosion[0].stage=0;
  663.                                                 }
  664.                                             }
  665.                                             for(i2=0; i2<100; i2++)
  666.                                             {
  667.                                                 particle[nextparticleslot].life=1;
  668.                                                 particle[nextparticleslot].pos.x=(float)(((int)(missle[i].pos.x/10)+x)*10+5);
  669.                                                 particle[nextparticleslot].pos.y=(float)(((int)(missle[i].pos.y/10)+y)*10+5);
  670.                                                 particle[nextparticleslot].pos.z=0.0f;
  671.                                                 particle[nextparticleslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  672.                                                 particle[nextparticleslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  673.                                                 particle[nextparticleslot].dir.z=(float)(rand()%100)/(float)100;
  674.                                                 nextparticleslot=0;
  675.                                                 while(particle[nextparticleslot].life>0)
  676.                                                 {
  677.                                                     nextparticleslot++;
  678.                                                     if(nextparticleslot==500)
  679.                                                     {
  680.                                                         nextparticleslot=0;
  681.                                                         particle[0].life=0;
  682.                                                     }
  683.                                                 }
  684.                                             }
  685.                                             missle[i].active=0;
  686.                                             smoke[missle[i].smoke].stillmoving=0;
  687.                                             if(i<nextmissleslot)
  688.                                                 nextmissleslot=0;
  689.                                             x=2;
  690.                                             y=2;
  691.                                         }
  692.                                     }
  693.                                 }
  694.                             }
  695.                         }
  696.                     }
  697.  
  698.                     if(missle[i].pos.x-3<0 || missle[i].pos.x+3>300 || missle[i].pos.y-3<0 || missle[i].pos.y+3>200)
  699.                     {
  700.                         missle[i].active=0;
  701.                         smoke[missle[i].smoke].stillmoving=0;
  702.                         if(i<nextmissleslot)
  703.                             nextmissleslot=0;
  704.                     }
  705.                     
  706.                     // Check if missle hit the wall
  707.                     if(wall>0 && missle[i].pos.x+3>150-3 && missle[i].pos.x-3<150+3)
  708.                     {
  709.                         missle[i].active=0;
  710.                         smoke[missle[i].smoke].stillmoving=0;
  711.                         if(i<nextmissleslot)
  712.                             nextmissleslot=0;
  713.                     }
  714.                 }
  715.             }
  716.  
  717.             GetCursorPos(&mousepos);
  718. //            SetCursorPos(screen_w/2,screen_h/2);
  719.             SetCursorPos(160, 120);
  720.             if(mousebutton[0])
  721.             {
  722. //                if(cameraangle + (mousepos.y - screen_h/2 )/10 < 0)
  723.                 if(cameraangle + (mousepos.y - 160)/10 < 0)
  724.                     cameraangle=0;
  725. //                else if(cameraangle + (mousepos.y - screen_h/2)/10 > 50)
  726.                 else if(cameraangle + (mousepos.y - 120)/10 > 50)
  727.                     cameraangle=50;
  728.                 else
  729. //                    cameraangle += (float)((float)mousepos.y - (float)screen_h/(float)2)/(float)10;
  730.                     cameraangle += (float)((float)mousepos.y - (float)120)/(float)10;
  731.             }
  732.  
  733.             if (!DrawGLScene())
  734.                 finished=TRUE;
  735.             if (key[DIK_ESCAPE] & 0x80)
  736.                 finished=TRUE;
  737.             if(key[VK_SPACE] & 0x80)
  738.             {
  739.                 framelimit=!framelimit;
  740.             }
  741.             if(key[DIK_1] & 0x80)
  742.             {
  743.                 fogenabled=!fogenabled;
  744.             }
  745.             if(key[DIK_2] & 0x80)
  746.             {
  747.                 timeofday=!timeofday;
  748.             }
  749.             if(key[DIK_3] & 0x80)
  750.             {
  751.                 if(raindensity>0)
  752.                     raindensity=0;
  753.                 else
  754.                     raindensity=100;
  755.             }
  756.  
  757.  
  758.             // END OF MAIN LOOP
  759.             QueryPerformanceCounter((LARGE_INTEGER*)&m);
  760.             fps=(float)1/(float)((float)m/(float)clckpersec-(float)t/(float)clckpersec);
  761.             if(framelimit)
  762.             {
  763.                 while(fps>25)
  764.                 {
  765.                     QueryPerformanceCounter((LARGE_INTEGER*)&m);
  766.                     fps=(float)1/(float)((float)m/(float)clckpersec-(float)t/(float)clckpersec);
  767.                 }
  768.             }
  769.         }
  770.     }
  771. }
  772.  
  773. void createbigexplosion(int xpos, int ypos)
  774. {
  775.     int i, x, y;
  776.     PlaySound("Data/Explode.wav", NULL, SND_ASYNC);
  777.     if(player[0].pos.x+3>xpos*10-10 &&
  778.        player[0].pos.x-3<xpos*10+20 &&
  779.        player[0].pos.y+3>ypos*10-10 &&
  780.        player[0].pos.y-3<ypos*10+20 &&
  781.        player[0].rebirth==0)
  782.     {
  783.         for(x=0; x<7; x++)
  784.         {
  785.             debris[nextdebrisslot].active=1;
  786.             debris[nextdebrisslot].pos.x=(float)((int)(player[0].pos.x/10)*10+5);
  787.             debris[nextdebrisslot].pos.y=(float)((int)(player[0].pos.y/10)*10+5);
  788.             debris[nextdebrisslot].pos.z=0.0f;
  789.             debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  790.             debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  791.             debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
  792.             debris[nextdebrisslot].color.x=0.6f;
  793.             debris[nextdebrisslot].color.y=0.1f;
  794.             debris[nextdebrisslot].color.z=0.0f;
  795.             while(debris[nextdebrisslot].active==1)
  796.             {
  797.                 nextdebrisslot++;
  798.                 if(nextdebrisslot==500)
  799.                 {
  800.                     nextdebrisslot=0;
  801.                     debris[0].active=0;
  802.                 }
  803.             }
  804.         }
  805.         player[0].rebirth=100;
  806.         player[0].lives--;
  807.         player[0].pos.x=(float)(player[0].startpos.x*10+5);
  808.         player[0].pos.y=(float)(player[0].startpos.y*10+5);
  809.         player[0].rot=0;
  810.     }
  811.     if(player[1].pos.x+3>xpos*10-10 &&
  812.        player[1].pos.x-3<xpos*10+20 &&
  813.        player[1].pos.y+3>ypos*10-10 &&
  814.        player[1].pos.y-3<ypos*10+20 &&
  815.        player[1].rebirth==0)
  816.     {
  817.         for(x=0; x<7; x++)
  818.         {
  819.             debris[nextdebrisslot].active=1;
  820.             debris[nextdebrisslot].pos.x=(float)((int)(player[1].pos.x/10)*10+5);
  821.             debris[nextdebrisslot].pos.y=(float)((int)(player[1].pos.y/10)*10+5);
  822.             debris[nextdebrisslot].pos.z=0.0f;
  823.             debris[nextdebrisslot].dir.x=(float)(rand()%100)/(float)100-(float)0.5;
  824.             debris[nextdebrisslot].dir.y=(float)(rand()%100)/(float)100-(float)0.5;
  825.             debris[nextdebrisslot].dir.z=(float)(rand()%200)/(float)100;
  826.             debris[nextdebrisslot].color.x=0.0f;
  827.             debris[nextdebrisslot].color.y=0.1f;
  828.             debris[nextdebrisslot].color.z=0.6f;
  829.             nextdebrisslot=0;
  830.             while(debris[nextdebrisslot].active==1)
  831.             {
  832.                 nextdebrisslot++;
  833.                 if(nextdebrisslot==500)
  834.                 {
  835.                     nextdebrisslot=0;
  836.                     debris[0].active=0;
  837.                 }
  838.             }
  839.         }
  840.         player[1].rebirth=100;
  841.         player[1].lives--;
  842.         player[1].pos.x=(float)(player[1].startpos.x*10+5);
  843.         player[1].pos.y=(float)(player[1].startpos.y*10+5);
  844.         player[1].rot=180;
  845.     }
  846.     for(i=0; i<200; i++)
  847.     {
  848.         particle[nextparticleslot].life=1;
  849.         particle[nextparticleslot].pos.x=(float)(xpos*10+5);
  850.         particle[nextparticleslot].pos.y=(float)(ypos*10+5);
  851.         particle[nextparticleslot].pos.z=0.0f;
  852.         particle[nextparticleslot].dir.x=(float)(rand()%200)/(float)100-(float)1;
  853.         particle[nextparticleslot].dir.y=(float)(rand()%200)/(float)100-(float)1;
  854.         particle[nextparticleslot].dir.z=(float)(rand()%200)/(float)100;
  855.         nextparticleslot=0;
  856.         while(particle[nextparticleslot].life>0)
  857.         {
  858.             nextparticleslot++;
  859.             if(nextparticleslot==500)
  860.             {
  861.                 nextparticleslot=0;
  862.                 particle[0].life=0;
  863.             }
  864.         }
  865.     }
  866.     for(y=-1; y<2; y++)
  867.     {
  868.         for(x=-1; x<2; x++)
  869.         {
  870.             if(xpos+x>=0 && xpos+x<30 && ypos+y>=0 && ypos+y<20)
  871.             {
  872.                 explosion[nextexplosionslot].stage=19;
  873.                 explosion[nextexplosionslot].pos.x=xpos+x;
  874.                 explosion[nextexplosionslot].pos.y=ypos+y;
  875.                 nextexplosionslot=0;
  876.                 while(explosion[nextexplosionslot].stage>0)
  877.                 {
  878.                     nextexplosionslot++;
  879.                     if(nextexplosionslot==50)
  880.                     {
  881.                         nextexplosionslot=0;
  882.                         explosion[0].stage=0;
  883.                     }
  884.                 }
  885.                 if(grid[xpos+x][ypos+y]==BRICK1)
  886.                     grid[xpos+x][ypos+y]=BRICK0;
  887.                 else if(grid[xpos+x][ypos+y]==BRICK0)
  888.                     grid[xpos+x][ypos+y]=EMPTY;
  889.                 else if(grid[xpos+x][ypos+y]==TREE)
  890.                     grid[xpos+x][ypos+y]=TRUNK;
  891.                 else if(grid[xpos+x][ypos+y]==TRUNK)
  892.                     grid[xpos+x][ypos+y]=EMPTY;
  893.                 else if(grid[xpos+x][ypos+y]==MINE)
  894.                     grid[xpos+x][ypos+y]=EMPTY;
  895.                 else if(grid[xpos+x][ypos+y]==LIFE_POWERUP || grid[xpos+x][ypos+y]==BRICK_POWERUP || grid[xpos+x][ypos+y]==MINE_POWERUP || grid[xpos+x][ypos+y]==MISSLE_POWERUP || grid[xpos+x][ypos+y]==GRENADE_POWERUP)
  896.                 {
  897.                     grid[xpos+x][ypos+y]=EMPTY;
  898.                     createbigexplosion(xpos+x, ypos+y);
  899.                 }
  900.             }
  901.         }
  902.     }
  903. }